In [2]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
import plotly.graph_objects as go
In [3]:
df= pd.read_csv("Df_Final.csv") 
df["FIPS"]=df["FIPS"].apply(str).str.zfill(5)
In [4]:
#df
Out[4]:
FIPS PovertyRate MedianFamilyIncome TractBlack TractHispanic lasnap1 lasnap10 lahunv1 lahunv10 TractPop ... Avg w Mortage Avg w/o Mortage Regions State Subregions Income_Group LogIncome LogPop LogMortgage Insecurity_Groups
0 01001 0.128072 64137.95386 0.176706 0.024005 0.033398 0.008940 0.012418 0.003070 54571 ... 141300 354 South Alabama East South Central Division Middle 11.068792 10.907258 11.85864057 Above Average
1 01003 0.138195 62404.36429 0.093847 0.043848 0.026746 0.000560 0.007649 0.000237 182265 ... 169300 365 South Alabama East South Central Division Middle 11.041390 12.113217 12.03942757 Above Average
2 01005 0.240037 43916.97214 0.468915 0.050515 0.049445 0.013646 0.015484 0.005828 27457 ... 92200 334 South Alabama East South Central Division Middle 10.690056 10.220376 11.43171541 Extreme
3 01007 0.170591 42271.68510 0.220249 0.017718 0.042426 0.000711 0.009792 0.000037 22915 ... 102700 344 South Alabama East South Central Division Middle 10.651873 10.039547 11.5395674 High
4 01009 0.174327 53069.87190 0.013276 0.080702 0.046853 0.001742 0.012559 0.000333 57322 ... 119800 335 South Alabama East South Central Division Middle 10.879365 10.956440 11.69357896 Average
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
3135 56037 0.123416 80227.47560 0.009999 0.152696 0.010114 0.000977 0.008209 0.000541 43806 ... 190900 361 West Wyoming Mountain Division Middle 11.292621 10.687526 12.15950501 Average
3136 56039 0.082756 89150.63642 0.002301 0.149854 0.004115 0.000000 0.002276 0.000000 21294 ... 689000 675 West Wyoming Mountain Division Middle 11.398083 9.966181 13.44299655 Average
3137 56041 0.140232 65319.39516 0.002604 0.087840 0.016383 0.000965 0.010021 0.000524 21118 ... 176700 342 West Wyoming Mountain Division Middle 11.087044 9.957881 12.08220866 Above Average
3138 56043 0.142366 62597.28724 0.002578 0.136177 0.011748 0.004197 0.004926 0.001535 8533 ... 160800 365 West Wyoming Mountain Division Middle 11.044477 9.051696 11.98791664 Average
3139 56045 0.123334 74728.71865 0.002913 0.029967 0.012483 0.001934 0.015628 0.005230 7208 ... 178200 380 West Wyoming Mountain Division Middle 11.221620 8.882947 12.09066179 Above Average

3140 rows × 22 columns

In [42]:
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
    counties = json.load(response)

    import plotly.express as px

fig = px.choropleth_mapbox(df, geojson=counties, locations='FIPS', color='Food Insecurity Rate',
                           color_continuous_scale="jet",
                           range_color=(0,0.4),
                           mapbox_style="carto-positron",
                           zoom=3, center = {"lat": 37.0902, "lon": -95.7129},
                           opacity=0.9,
                           labels={'Food Insecurity Rate':'Food Insecurity Rate'}
                          )
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
In [9]:
print(df['MedianFamilyIncome'].nlargest(1))
print(df['MedianFamilyIncome'].nsmallest(1))
2923    157191.8651
Name: MedianFamilyIncome, dtype: float64
1425    26621.94145
Name: MedianFamilyIncome, dtype: float64
In [12]:
fig = px.histogram(df, x="Food Insecurity Rate", color="Regions")
fig.show()
In [13]:
fig = px.histogram(df, x="Food Insecurity Rate", color="Subregions")
fig.show()
In [14]:
fig = px.histogram(df, x='MedianFamilyIncome', color='Insecurity_Groups')
fig.show()
In [15]:
fig = px.histogram(df, x="Food Insecurity Rate", color="Income_Group")
fig.show()
In [18]:
fig = px.box(df, x="Subregions", y="Food Insecurity Rate", points="all", color= "Income_Group")
fig.show()
In [19]:
fig = px.box(df, x="Subregions", y="Food Insecurity Rate", points="all", color= "Subregions")
fig.show()
In [24]:
fig = px.histogram(df, x="Food Insecurity Rate", color="Regions")
fig.show()
In [25]:
fig = px.histogram(df, x="Food Insecurity Rate", color="Income_Group")
fig.show()
In [26]:
Score_Card=df.groupby('Income_Group').describe()
In [28]:
fig = px.box(df, x="Regions", y="Food Insecurity Rate", points="all", color= "Income_Group")
fig.show()
In [29]:
fig = px.box(df, x="Regions", y="Food Insecurity Rate", points="all", color= "Regions")
fig.show()
In [40]:
fig = px.scatter(df, x="Food Insecurity Rate", y="MedianFamilyIncome", color="Subregions")
fig.show()
In [41]:
fig = px.scatter(df, x="Food Insecurity Rate", y="MedianFamilyIncome", color="Regions")
fig.show()
In [34]:
#Score_Card.to_csv("Df_Score_Card") 
In [35]:
Score_Card
Out[35]:
PovertyRate MedianFamilyIncome ... LogIncome LogPop
count mean std min 25% 50% 75% max count mean ... 75% max count mean std min 25% 50% 75% max
Income_Group
High 10.0 0.054391 0.014605 0.038254 0.045789 0.051003 0.058653 0.087542 10.0 131664.919950 ... 11.809676 11.965222 10.0 12.191512 1.508865 9.419953 11.882756 12.609644 13.001791 13.894068
Low 190.0 0.297190 0.065482 0.047208 0.253807 0.294577 0.339830 0.478627 190.0 36370.134246 ... 10.575431 10.598553 190.0 9.525205 0.885037 6.889591 9.093554 9.503999 10.021535 13.560320
Middle 2940.0 0.161046 0.055880 0.010000 0.119639 0.157625 0.195493 0.444440 2940.0 58932.670830 ... 11.077911 11.695048 2940.0 10.308911 1.478281 4.406719 9.355133 10.223376 11.171990 16.099790

3 rows × 112 columns